﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Bills.Database;
using System.Data.OleDb;



namespace Bills
{
    public partial class billsApp : Form
    {
        // lol who needs arrays?
        private string companyInput;
        private string IDflag = "0";        
        private double dueAmount;
        private string dateDueInput;

        dtableProvider DB = new dtableProvider();

        public billsApp()
        {
            InitializeComponent();
            DB.ConnectDB(dataGridView1);
            
        }

        private void billsApp_Load(object sender, EventArgs e)
        {

        }

        private void addButton_Click(object sender, EventArgs e)
        {   
            //Assigning textbox values to variables and passing to dtableProvider to Update the database with these parameters.
            if (!txtID.Text.Equals(""))
            {
            IDflag = txtID.Text;
            }
            companyInput = txtCompany.Text;
            dueAmount = GetAmountDue(txtAmount.Text);            
            dateDueInput = txtDateDue.Text;
            DB.Update(companyInput, dueAmount, dateDueInput, Convert.ToInt16(IDflag));
            dataGridView1.Refresh();
        }

        private void removeButton_Click(object sender, EventArgs e)
        {
        }

        private void billsListView_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        private void companyTextBox_TextChanged(object sender, EventArgs e)
        {

        }

        private void idTextBox_TextChanged(object sender, EventArgs e)
        {

        }

        private double GetAmountDue(string amountText)
        {
            double amount;
            //need masked control to validate format    -http://msdn.microsoft.com/en-us/library/bbabas53.aspx
            if (amountText.Contains("."))
            {

                amount = Convert.ToDouble(amountText);
            }
            else
            {
                amount = 0.00;
            }

            
            return amount;

        }

        private void exitButton_Click(object sender, EventArgs e)
        {
            this.Close();
        }


    }
}
